package com.gl.doc.model.container;

import com.gl.doc.model.WordXml;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * wordXml存储容器
 */
@Data
public class WordXmlContainer {
    /**
     * 存储word相关xml，目前只是批注相关xml。
     */
    private Map<String, WordXml> commentXmlMap;

    /**
     * 构造器
     */
    public WordXmlContainer() {
        this.init();
    }

    /**
     * 初始化xml
     * key命名规则为：文件名称+PartName;
     */
    public void init() {
        this.commentXmlMap = new HashMap<>();
        commentXmlMap.put("document.xml-people", new WordXml("document.xml-commentsExtended", "Relationship Id=\"rId1001\" Type=\"http://schemas.microsoft.com/office/2011/relationships/people\" Target=\"people.xml\""));
        commentXmlMap.put("document.xml-commentsExtended", new WordXml("document.xml-commentsExtended", "Relationship Id=\"rId1002\" Type=\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\" Target=\"commentsExtended.xml\""));
        commentXmlMap.put("document.xml-comments", new WordXml("document.xml-comments", "Relationship Id=\"rId1003\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments\" Target=\"comments.xml\""));
        commentXmlMap.put("[Content_Types].xml-comments", new WordXml("[Content_Types].xml-comments", "Override PartName=\"/word/comments.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml\""));
        commentXmlMap.put("[Content_Types].xml-commentsExtended", new WordXml("[Content_Types].xml-commentsExtended", "Override PartName=\"/word/commentsExtended.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml\""));
    }

    /**
     * 根据名称获取一个word Xml
     *
     * @param name xml名称
     * @return wordXml
     */
    public WordXml getWordXmlByName(String name) {
        return commentXmlMap.get(name);
    }

    /**
     * 根据名称获取一个xml字符串
     *
     * @param name xml名称
     * @return xml字符串
     */
    public String getWordXmlString(String name) {
        return this.getWordXmlByName(name).getXml();
    }
}
